package com.qf.six.ssm.service.product.impl;


import com.qf.six.ssm.commen.exception.ServiceException;
import com.qf.six.ssm.commen.request.CommodityParam;
import com.qf.six.ssm.commen.vo.ResponseCode;
import com.qf.six.ssm.entity.Commodity;
import com.qf.six.ssm.mapper.product.CommodityMapper;
import com.qf.six.ssm.service.product.CommodityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZL
 */
@Service
public class CommodityServiceImpl implements CommodityService {
    @Resource
    CommodityMapper commodityMapper;
    @Override
    public Commodity selectCo(String id) {
        Commodity commodity = commodityMapper.select(id);
        if(commodity != null){
            return commodity;
        } else {
            throw new ServiceException(ResponseCode.ERROR);

        }
    }

    @Override
    public List<Commodity> select() {
        List<Commodity> list = commodityMapper.selectList();
        if(list.size() > 0){
            return list;
        } else {
            throw new ServiceException(ResponseCode.ERROR);
        }
    }

    @Override
    public Commodity update(Commodity commodity) {
        return commodityMapper.update(commodity);
    }

    @Override
    public int insert(CommodityParam param) {
        int count = commodityMapper.insert(param);
        if(count > 0){
            return count;
        } else {
            throw new ServiceException(ResponseCode.ERROR);

        }
    }

    @Override
    public int del(String cid) {
        int count = commodityMapper.del(cid);
        if(count > 0){
            return count;
        } else {
            throw new ServiceException(ResponseCode.ERROR);

        }
    }


}
